<?php

namespace Saber\Helper\Basis;


class Json
{

    /**
     * @param array $data
     * @param int   $options
     * @param int   $depth
     *
     * @return false|string
     */
    public static function EnCode (array $data , $options = JSON_UNESCAPED_UNICODE , $depth = 512) : string {

        return json_encode ($data , $options , $depth);
    }

    /**
     * @param string $data
     * @param bool   $assoc
     * @param int    $depth
     * @param int    $options
     *
     * @return mixed
     * @throws \JsonException
     */
    public static function DeCode (string $data , bool $assoc = false , int $depth = 512 , int $options = 0) {

        $data = json_decode ($data , $assoc , $depth , $options);
        if ( json_last_error () ) {
            throw new \JsonException (json_last_error_msg ());
        }

        return $data;
    }

}
